<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 -->
<!-- 
* @desc:任务实例搜索组件
* @fileName:InstanceSearch.vue
* @author:zhouyongjie@yzbdl.ac.cn
* @date:2022-4-12
!-->
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { Search } from "@element-plus/icons-vue";
// 接受父组件传回
const props = defineProps({
  // 查询方法
  searchFunc: Function as any,
  status: Number as any,
});
// 定义名称值
const userValue = ref("");
// 定义资源类型选择值
const eventValue = ref("");
// 定义资源日期范围
let dateValue = ref("");
// 资源类型下拉框选择项
const options = [
  {
    value: "1",
    label: "成功",
  },
  {
    value: "2",
    label: "失败",
  },
  {
    value: "3",
    label: "初始化失败",
  },
  {
    value: "4",
    label: "初始化中",
  },
  {
    value: "5",
    label: "运行中",
  },
  {
    value: "6",
    label: "跳过",
  },
  {
    value: "7",
    label: "已重试",
  },

  {
    value: "8",
    label: "监控异常",
  },
  {
    value: "9",
    label: "暂停（手动）",
  },
  {
    value: "10",
    label: "停止（手动）",
  },
  {
    value: "11",
    label: "等待中",
  },
];

/**
 * @description:查询方法
 * @return void
 */
const serarch = () => {
  if (dateValue.value === null) {
    dateValue.value = "";
  }
  // 组装查询参数
  let serachData = {
    userValue: userValue.value,
    beginTime: dateValue.value[0],
    endTime: dateValue.value[1],
    status: eventValue.value,
  };
  // 调用父组件传递的方法进行查询
  props.searchFunc(serachData);
};

/**
 * @description:选择时间
 * @return void
 */
const changeTime = () => {
  serarch();
};

/**
 * @description:状态筛选
 * @return void
 */
const changeSelect = () => {
  serarch();
};
onMounted(() => {
  if (props.status) {
    eventValue.value = props.status;
    serarch();
  }
});
</script>

<template>
  <div class="page-search">
    <!-- 列表文字 -->
    <div class="page-title-words">任务实例执行统计</div>
    <!-- 名称查询 -->
    <el-input
      class="page-search-userInput"
      v-model="userValue"
      @clear="serarch"
      @keyup.enter.native="serarch"
      clearable
      :suffix-icon="Search"
      placeholder="请输入任务名称/资源名称/服务节点名称"
    ></el-input>
    <!-- 时间范围 -->
    <div class="dataPicker">
      <el-date-picker
        v-model="dateValue"
        format="YYYY/MM/DD"
        @change="changeTime"
        value-format="YYYY-MM-DD HH:mm:ss"
        type="daterange"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
    </div>

    <!-- 事件选择 -->
    <el-select
      class="page-search-eventChoose"
      v-model="eventValue"
      @change="changeSelect"
      clearable
      placeholder="状态"
      size="large"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </div>
</template>

<style scoped lang="scss">
.page-search {
  display: flex;
  justify-content: flex-end;
  :deep(.el-input__wrapper) {
    height: 30px;
    border-radius: 0;
    background-color: #f2f2f6 !important;
    box-shadow: unset !important;
  }
  :deep(.el-date-editor--daterange) {
    border-radius: 0;
    background-color: #f2f2f6 !important;
    box-shadow: unset !important;
  }
  .dataPicker {
    width: 350px;
  }
  .page-title-words {
    font-size: 16px;
    color: #000;
    flex: 1;
  }
  .page-search-dateChoose {
    width: 110px;
  }
  .page-search-userInput {
    width: 310px;
    margin-left: 15px;
    margin-right: 15px;
  }
  .page-search-eventChoose {
    width: 140px;
    margin-right: 15px;
    margin-left: 15px;
    height: 30px;
  }
  .el-button {
    width: 70px;
    border-radius: 0;
    background-color: #f2f2f6;
    color: #000;
  }
}
</style>
